<template>
  <el-container class="station-container">
    <!-- 左侧菜单 -->
    <el-aside width="200px">
      <div class="logo-container">
        <h3 class="site-title">再生道站点管理</h3>
      </div>
      <el-menu
        :default-active="$route.path"
        class="station-menu"
        background-color="#304156"
        text-color="#fff"
        active-text-color="#67c23a"
        router
      >
        <el-menu-item index="/station/management">
          <i class="el-icon-s-home"></i>
          <span>站点概览</span>
        </el-menu-item>
        <el-menu-item index="/station/orders">
          <i class="el-icon-s-order"></i>
          <span>订单管理</span>
        </el-menu-item>
        <el-menu-item index="/station/announcement">
          <i class="el-icon-bell"></i>
          <span>公告查看</span>
        </el-menu-item>
        <el-menu-item index="/station/pricing">
          <i class="el-icon-s-order"></i>
          <span>废品定价</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 右侧内容 -->
    <el-container>
      <el-header>
        <div class="header-title">
          <i class="el-icon-s-fold toggle-btn" @click="isCollapse = !isCollapse"></i>
          <span>{{ currentTitle }}</span>
        </div>
        <div class="user-info">
          <el-dropdown trigger="click" @command="handleCommand">
            <span class="user-dropdown">
              {{ userName }} <i class="el-icon-arrow-down"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="profile">个人信息</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'StationLayout',
  data() {
    return {
      userName: localStorage.getItem('userName') || '站点管理员',
      isCollapse: false,
      menuTitles: {
        '/station/management': '站点概览',
        '/station/orders': '订单管理',
        '/station/announcement': '公告查看',
        '/station/material': '物料管理'
      }
    }
  },
  computed: {
    currentTitle() {
      return this.menuTitles[this.$route.path] || '站点管理系统'
    }
  },
  methods: {
    handleCommand(command) {
      if (command === 'logout') {
        this.handleLogout()
      } else if (command === 'profile') {
        this.$router.push('/station/profile')
      }
    },
    handleLogout() {
      this.$confirm('确认退出登录?', '提示', {
        type: 'warning'
      }).then(() => {
        localStorage.clear()
        this.$router.push('/login')
        this.$message.success('已退出登录')
      })
    }
  },
  watch: {
    isCollapse(val) {
      document.querySelector('.station-container .el-aside').style.width = val ? '64px' : '200px'
    }
  }
}
</script>

<style scoped>
.station-container {
  height: 100vh;
}

.station-menu {
  height: 100%;
  border-right: none;
}

.el-header {
  background-color: #fff;
  color: #333;
  line-height: 60px;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.header-title {
  font-size: 18px;
  font-weight: bold;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.el-aside {
  background-color: #304156;
  color: #fff;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
  height: calc(100vh - 60px);
  overflow-y: auto;
}
</style> 